-- flush_creep.lua
require("timers")
-- local G = require("const")
local flush_creep = {}
local creepWaves = {
    -- 第一波
    { { id = "npc_dota_neutral_kobold1", health = 5, armor = 0, move_speed = 300, gold = 1, quantity = 10, index = 1, cn_name = "狗头人" } },
    { { id = "npc_dota_neutral_kobold_tunneler1", health = 11, armor = 3, move_speed = 320, gold = 2, quantity = 10, index = 1, cn_name = "狗头人挖掘工" } },
    { { id = "npc_dota_neutral_kobold_taskmaster1", health = 15, armor = 3, move_speed = 320, gold = 3, quantity = 10, index = 1, cn_name = "狗头人工头领" } },
    { { id = "npc_dota_neutral_centaur_outrunner1", health = 25, armor = 0, move_speed = 300, gold = 4, quantity = 10, index = 1, cn_name = "半人马先驱" } },
    { { id = "npc_dota_neutral_centaur_khan1", health = 50, armor = 3, move_speed = 320, gold = 5, quantity = 10, index = 1, cn_name = "半人马汗" } },
    { { id = "npc_dota_neutral_fel_beast1", health = 75, armor = 3, move_speed = 320, gold = 6, quantity = 10, index = 1, cn_name = "恶魔兽" } },
    { { id = "npc_dota_neutral_polar_furbolg_champion1", health = 100, armor = 0, move_speed = 300, gold = 7, quantity = 10, index = 1, cn_name = "极地熊怪勇士" } },
    { { id = "npc_dota_neutral_polar_furbolg_ursa_warrior1", health = 160, armor = 3, move_speed = 320, gold = 8, quantity = 10, index = 1, cn_name = "极地熊怪战士" } },
    { { id = "npc_dota_neutral_mud_golem1", health = 200, armor = 3, move_speed = 320, gold = 9, quantity = 10, index = 1, cn_name = "泥石人" } },
    { { id = "npc_dota_neutral_mud_golem_split1", health = 250, armor = 0, move_speed = 300, gold = 10, quantity = 10, index = 1, cn_name = "泥石人分裂体" } },
    { { id = "npc_dota_neutral_mud_golem_split_doom1", health = 300, armor = 3, move_speed = 320, gold = 11, quantity = 10, index = 1, cn_name = "泥石人末日分裂体" } },
    { { id = "npc_dota_neutral_ogre_mauler1", health = 350, armor = 3, move_speed = 320, gold = 12, quantity = 10, index = 1, cn_name = "食人魔殴打者" } },
    { { id = "npc_dota_neutral_ogre_magi1", health = 500, armor = 0, move_speed = 300, gold = 13, quantity = 10, index = 1, cn_name = "食人魔魔法师" } },
    { { id = "npc_dota_neutral_giant_wolf1", health = 750, armor = 3, move_speed = 320, gold = 14, quantity = 10, index = 1, cn_name = "巨狼" } },
    { { id = "npc_dota_neutral_alpha_wolf1", health = 1000, armor = 3, move_speed = 320, gold = 15, quantity = 10, index = 1, cn_name = "首领狼" } },
    { { id = "npc_dota_neutral_wildkin1", health = 1250, armor = 0, move_speed = 300, gold = 16, quantity = 10, index = 1, cn_name = "野生金翼鸟" } },
    { { id = "npc_dota_neutral_enraged_wildkin1", health = 1500, armor = 3, move_speed = 320, gold = 17, quantity = 10, index = 1, cn_name = "狂怒金翼鸟" } },
    { { id = "npc_dota_neutral_satyr_soulstealer1", health = 2000, armor = 3, move_speed = 320, gold = 18, quantity = 10, index = 1, cn_name = "萨特窃魂者" } },
    { { id = "npc_dota_neutral_satyr_hellcaller1", health = 2500, armor = 0, move_speed = 300, gold = 19, quantity = 10, index = 1, cn_name = "萨特地狱召唤师" } },
    { { id = "npc_dota_neutral_jungle_stalker1", health = 3000, armor = 3, move_speed = 320, gold = 20, quantity = 10, index = 1, cn_name = "丛林追猎者" } },
    { { id = "npc_dota_neutral_elder_jungle_stalker1", health = 3500, armor = 3, move_speed = 320, gold = 21, quantity = 10, index = 1, cn_name = "长者丛林追猎者" } },
    { { id = "npc_dota_neutral_blue_dragonspawn_sorcerer1", health = 4000, armor = 0, move_speed = 300, gold = 22, quantity = 10, index = 1, cn_name = "蓝龙族巫师" } },
    { { id = "npc_dota_neutral_blue_dragonspawn_overseer1", health = 5000, armor = 3, move_speed = 320, gold = 23, quantity = 10, index = 1, cn_name = "蓝龙族监工" } },
    { { id = "npc_dota_neutral_rock_golem1", health = 15, armor = 7000, move_speed = 320, gold = 24, quantity = 10, index = 1, cn_name = "岩石魔像" } },
    { { id = "npc_dota_neutral_granite_golem1", health = 9000, armor = 0, move_speed = 300, gold = 25, quantity = 10, index = 1, cn_name = "花岗岩魔像" } },
    { { id = "npc_dota_neutral_big_thunder_lizard1", health = 11000, armor = 3, move_speed = 320, gold = 26, quantity = 10, index = 1, cn_name = "大雷蜥蜴" } },
    { { id = "npc_dota_neutral_small_thunder_lizard1", health = 14000, armor = 3, move_speed = 320, gold = 27, quantity = 10, index = 1, cn_name = "小雷蜥蜴" } },
    { { id = "npc_dota_neutral_gnoll_assassin1", health = 19000, armor = 17000, move_speed = 300, gold = 28, quantity = 10, index = 1, cn_name = "豺狼人刺客" } },
    { { id = "npc_dota_neutral_ghost1", health = 21000, armor = 3, move_speed = 320, gold = 29, quantity = 10, index = 1, cn_name = "幽灵" } },
    { { id = "npc_dota_neutral_dark_troll1", health = 23000, armor = 3, move_speed = 320, gold = 30, quantity = 10, index = 1, cn_name = "黑暗巨魔" } },
    { { id = "npc_dota_neutral_dark_troll_warlord1", health = 25000, armor = 3, move_speed = 320, gold = 31, quantity = 10, index = 1, cn_name = "黑暗巨魔督军" } },
    { { id = "npc_dota_neutral_satyr_trickster1", health = 27000, armor = 3, move_speed = 320, gold = 32, quantity = 10, index = 1, cn_name = "萨特欺诈者" } },
    { { id = "npc_dota_neutral_forest_troll_berserker1", health = 29000, armor = 0, move_speed = 300, gold = 33, quantity = 10, index = 1, cn_name = "森林巨魔狂战士" } },
    { { id = "npc_dota_neutral_forest_troll_high_priest1", health = 31000, armor = 3, move_speed = 320, gold = 34, quantity = 10, index = 1, cn_name = "森林巨魔高级祭司" } },
    { { id = "npc_dota_neutral_harpy_scout1", health = 33000, armor = 3, move_speed = 320, gold = 35, quantity = 10, index = 1, cn_name = "鹰身女妖侦查者" } },
    { { id = "npc_dota_neutral_harpy_storm1", health = 35000, armor = 3, move_speed = 320, gold = 36, quantity = 10, index = 1, cn_name = "鹰身女妖风暴女巫" } },
    { { id = "npc_dota_neutral_black_drake1", health = 40000, armor = 3, move_speed = 320, gold = 37, quantity = 10, index = 1, cn_name = "黑色幼龙" } },
    { { id = "npc_dota_neutral_black_dragon1", health = 45000, armor = 0, move_speed = 300, gold = 38, quantity = 10, index = 1, cn_name = "黑龙" } }
}

-- 定义刷怪地点的单位名称数组
local spawnUnitNames = {
    "a1"
}

-- 其他常量
local CREEP_COUNT = 10                     -- 每波生成的小兵数量
local EVERY_CREEP_INTERVAL = 1           -- 每个小兵之间的间隔时间（秒）
local SPAWN_INTERVAL = 5                  -- 刷兵间隔（秒）
local WAVE_NUMBER_CURRENT = 0              -- 当前波数

-- 当前信息
local HEALTH_CURRENT = 10
local DAMAGE_CURRENT = 10
local EXP_CURRENT = 1
local MONEY_CURRENT = 1

-- 成长信息
local HEALTH_INCREMENT = 10               -- 每波小兵生命值增加量
local DAMAGE_INCREMENT = 3                -- 每波小兵攻击力增加量
local EXP_INCREMENT = 0
local MONEY_INCREMENT = 0

function flush_creep.SendCreepInfoToUI()
    local creepInfo = {
        creepCount = CREEP_COUNT,
        everyCreepInterval = EVERY_CREEP_INTERVAL,
        spawnInterval = SPAWN_INTERVAL,
        waveNumberCurrent = WAVE_NUMBER_CURRENT,
        healthCurrent = HEALTH_CURRENT,
        damageCurrent = DAMAGE_CURRENT,
        expCurrent = EXP_CURRENT,
        moneyCurrent = MONEY_CURRENT,
        healthIncrement = HEALTH_INCREMENT,
        damageIncrement = DAMAGE_INCREMENT,
        expIncrement = EXP_INCREMENT,
        moneyIncrement = MONEY_INCREMENT
    }
    --print("后端发送信息:".. creepInfo)
    CustomGameEventManager:Send_ServerToAllClients("update_creep_info", creepInfo)
end

local currentWave = 1
local a = 20;
local bb = 10;
local c = 1.04;
local currH = 200;
local dd = {
	"npc_td_creep_golem",
	"npc_td_creep_centaur",
	"npc_td_creep_wildwing",
	"npc_td_creep_wolf",
	"npc_td_creep_granite_golem",
	"npc_td_creep_hawk",
	"npc_td_creep_ogre_magi",
	"npc_td_creep_necro_warrior",
	"npc_td_creep_necro_archer",
}

function flush_creep.SpawnCreeps()

    local spawnUnitName = "a1"  -- 假设您已经定义了刷怪点的名称
    local spawnUnit = Entities:FindByName(nil, spawnUnitName)
    local spawnLocation = spawnUnit:GetAbsOrigin()

    if currentWave ~= 1 then
        currH = currH*c + a + bb*(currentWave*2-1);
    end

    for a,b in pairs (dd) do
        local creep = CreateUnitByName(b, spawnLocation, true, nil, nil, DOTA_TEAM_BADGUYS)
        creep:SetMaxHealth(currH)
        creep:SetBaseMaxHealth(currH)
        creep:SetHealth(currH)
        creep:SetBaseMoveSpeed(100)
        creep:SetMinimumGoldBounty(1)
        local pathEntity = Entities:FindByName(nil, "path")
        creep:SetInitialGoalEntity(pathEntity)
    end
    -- Timers:CreateTimer(i * EVERY_CREEP_INTERVAL, function()
    --     local creep = CreateUnitByName("npc_td_creep_golem", spawnLocation, true, nil, nil, DOTA_TEAM_BADGUYS)
    --     creep:SetHealth(1)
    --     creep:SetBaseMoveSpeed(300)
    --     creep:SetMinimumGoldBounty(1)
    --     -- 设置单位的初始目标点
    --     local pathEntity = Entities:FindByName(nil, "path")
    --     creep:SetInitialGoalEntity(pathEntity)

    --     return nil
    -- end)

    -- 准备下一波
    currentWave = currentWave + 1;
    return SPAWN_INTERVAL
end




return flush_creep
